package DesginFotmat;

import java.util.concurrent.locks.LockSupport;

public class OutputInturn3 {
    static Thread a;
    static Thread b;
    static Thread c;
    public static void main(String[] args) {
        ParkUnPark parkUnPark = new ParkUnPark(5);
        a = new Thread(()->{
            parkUnPark.print("a",b);
        },"t1");

        b = new Thread(()->{
            parkUnPark.print("b",c);
        },"t2");

        c = new Thread(()->{
            parkUnPark.print("c",a);
        },"t3");

        a.start();
        b.start();
        c.start();

        LockSupport.unpark(a);
    }

}

class ParkUnPark{
    private int loopNumber;

    public ParkUnPark(int loopNumber) {
        this.loopNumber = loopNumber;
    }

    public void print(String str, Thread next){
        for(int i=0;i<loopNumber;i++){
            LockSupport.park();
            System.out.println(str);
            LockSupport.unpark(next);
        }
    }
}
